$(function(){


  tinymce.init({
    selector: '#content',  // 匹配页面中的 textarea 选择器
    language: 'zh_CN',     // 显示中文界面，注意大小写
  })


    $.ajax({
        type: 'get',
        url: 'http://localhost:8080/api/v1/admin/category/list',
        headers:{
          Authorization:localStorage.getItem('token')
         },
        success: (backData) => {
      let res=  template('temp',backData)
      $('.category').html(res)
        },
      })
    $('#matou').on('click',function(e){
        e.preventDefault()
     let f=new FormData($('form')[0])
    let content = tinyMCE.editors['content'].getContent();
    f.append('content', content);
     f.set('state','已发布')
     console.log( f.get('title'))
     console.log( f.get('cover'));
     console.log( f.get('categoryId'));
     console.log(f.get('content'));
     console.log(f.get('date'));
  

     $.ajax({
         type:'post',
         url:'http://localhost:8080/api/v1/admin/article/publish',
         data:f,
         contentType:false,
         processData:false,
         headers:{
            Authorization:localStorage.getItem('token')
           },
         success:function(backData){
        
         window.location.href='./article_list.html  '
         }
     })
      })
    
      $('.btn-draft').on('click',function(e){
        e.preventDefault()
        let f=new FormData($('form')[0])
       let content = tinyMCE.editors['content'].getContent();
       f.append('content', content);
        f.set('state','')
        console.log( f.get('title'))
        console.log( f.get('cover'));
        console.log( f.get('categoryId'));
        console.log(f.get('content'));
        console.log(f.get('date'));
     
   
        $.ajax({
            type:'post',
            url:'http://localhost:8080/api/v1/admin/article/publish',
            data:f,
            contentType:false,
            processData:false,
            headers:{
               Authorization:localStorage.getItem('token')
              },
            success:function(backData){
           
            window.location.href='./article_list.html  '
            }
        })
      })


















      $('#inputCover').on('change',function(){
          let fi=this.files[0]
          let url=URL.createObjectURL(fi)
          $('.article_cover').attr('src',url)
      })


$

})
